﻿namespace Sidvall.IdentityManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AspNetUserClaims : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.IdentityManager.Data.IAspNetUserClaims
    {
        #region Public Members

        #region ClaimType

        private string _ClaimType;
        partial void OnBeforeClaimTypePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterClaimTypePropertyChanged();
        public string ClaimType
        { 
            get
            {
                return _ClaimType;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ClaimType = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ClaimType);
                    OnBeforeClaimTypePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ClaimType", eventData.Value, true, true);
                        OnAfterClaimTypePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region ClaimValue

        private string _ClaimValue;
        partial void OnBeforeClaimValuePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterClaimValuePropertyChanged();
        public string ClaimValue
        { 
            get
            {
                return _ClaimValue;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _ClaimValue = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _ClaimValue);
                    OnBeforeClaimValuePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("ClaimValue", eventData.Value, true, true);
                        OnAfterClaimValuePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region Id

        private System.Nullable<int> _Id;
        partial void OnBeforeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterIdPropertyChanged();
        public System.Nullable<int> Id
        { 
            get
            {
                return _Id;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _Id = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _Id);
                    OnBeforeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("Id", eventData.Value, true, true);
                        OnAfterIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region UserId

        private string _UserId;
        partial void OnBeforeUserIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserIdPropertyChanged();
        public string UserId
        { 
            get
            {
                return _UserId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _UserId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserId);
                    OnBeforeUserIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("UserId", eventData.Value, true, true);
                        OnAfterUserIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public AspNetUsers AspNetUser { get; set; }
        #region LoadAspNetUserAsync

        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync()
        {
            return await LoadAspNetUserAsync(false, true, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUsers> LoadAspNetUserAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.IdentityManager.Data.Fields.AspNetUsersField, global::Sidvall.IdentityManager.Data.Relations.AspNetUsersRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.IdentityManager.SystemContext.Current.DataPortal.AspNetUserClaimsManager.LoadAspNetUserAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters).ConfigureAwait(false);

            return this.AspNetUser;
        }
        public AspNetUsers LoadAspNetUser(AspNetUsers item)
        {
            LoadInstanceField("AspNetUser", item, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public AspNetUserClaims Copy()
        {
            return global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Copy(this);
        }
        public AspNetUserClaims Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserClaims item)
        {
            global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Import(this, item);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IAspNetUserClaims item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Import(this, item, settings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AspNetUserClaims> SaveItemAsync()
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.DataPortal.AspNetUserClaimsManager.SaveItemAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserClaims> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.DataPortal.AspNetUserClaimsManager.SaveItemAsync(this, mode).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserClaims> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.DataPortal.AspNetUserClaimsManager.SaveItemAsync(this, settings).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<AspNetUserClaims> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.DataPortal.AspNetUserClaimsManager.SaveItemAsync(this, settings, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Initialize(this, settings);
        }

        #endregion

        #region IAspNetUserClaims Members

        string global::Sidvall.IdentityManager.Data.IAspNetUserClaims.ClaimType
        {
            get
            {
                return this._ClaimType;
            }
            set
            {
                this._ClaimType = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserClaims.ClaimValue
        {
            get
            {
                return this._ClaimValue;
            }
            set
            {
                this._ClaimValue = value;
            }
        }
        System.Nullable<int> global::Sidvall.IdentityManager.Data.IAspNetUserClaims.Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                this._Id = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetUserClaims.UserId
        {
            get
            {
                return this._UserId;
            }
            set
            {
                this._UserId = value;
            }
        }
        global::Sidvall.IdentityManager.Data.IAspNetUsers global::Sidvall.IdentityManager.Data.IAspNetUserClaims.AspNetUser
        {
            get
            {
                return this.AspNetUser;
            }
            set
            {
                this.AspNetUser = (AspNetUsers)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AspNetUserClaims()
        {
        }
        public AspNetUserClaims(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public AspNetUserClaims(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.IdentityManager.SystemContext.Current.EntityFacade.AspNetUserClaimsManager.Initialize(this);
        }

        #endregion
    }
}